Psignal(2) Oct. 1, 1991 Psignal(2) NAME Psignal - change the way a signal is handled SYNOPSIS #include LONG Psignal(WORD sig, LONG handler); DESCRIPTION Psignal changes the handling of the signal indicated by sig (which must be between 1 and 31; symbolic constants for sym- bols are defined in the file signal.h). The new signal handler applies to this process only. If handler is SIG_DFL, then the default action for the sig- nal will occur when the signal is delivered to the process. If handler is SIG_IGN, then the signal will be ignored by the process, and delivery of the signal will have no notice- able effect (in particular, the signal will not interrupt the Pause system call, q.v.). If the signal is pending at the time of the Psignal call, it is discarded. If handler is some other value, it is assumed to be the address of a user function that will be called when the sig- nal is delivered to the process. The user function is called with a single LONG argument on the stack, which is the number of the signal being delivered (this is done so that processes may use the same handler for a number of different signals). While the signal is being handled, it is blocked from delivery; thus, signal handling is "reliable" (unlike Version 7 and early System V Unix implementations, in which delivery of a second signal while it was being handled could kill the process). Also note that, unlike some versions of Unix, the signal handling is *not* reset to the default action before the handler is called; it remains set to the given signal handler. The signal handler must either return (via a normal 680x0 rts instruction) or call the Psigreturn system call to indi- cate when signal handling is complete; in both cases, the signal will be unblocked. Psigreturn also performs some internal clean-up of the kernel stack that is necessary if the signal handler is not planning to return (for example, if the C longjmp() function is to be used to continue execu- tion at another point in the program). Signal handlers may make any GEMDOS, BIOS, or XBIOS system calls freely. GEM AES and VDI calls should not be made in a signal handler. Version 0.9 Last change: MiNT Programmer's Manual 1 Psignal(2) Oct. 1, 1991 Psignal(2) Note that calling Psignal to change behavior of a signal has the side effect of unmasking that signal, so that delivery is possible. This is done so that processes may, while han- dling a signal, reset the behavior and send themselves another instance of the signal, for example in order to suspend themselves while handling a job control signal. Signal handling is preserved across Pfork and Pvfork calls. Signals that are ignored by the parent are also ignored by the child after a Pexec call; signals that were being caught for handling in a function are reset in the child to the default behavior. RETURNS The old value of the signal handler on success; this will be either SIG_DFL, SIG_IGN, or a function address. ERANGE if sig is not a legal signal. EACCDN if the signal may not be caught by the user SEE ALSO Pkill(2), Psigblock(2), Psigreturn(2) BUGS Signal handling can be nested only a small (around 3) number of times, i.e. if 4 signals are delivered to a process, and the process has established handlers for all 4, and none of the handlers has returned or called Psigreturn, then there is a very good chance of a stack overflow killing the process off. In practice, this is unlikely to happen. Version 0.9 Last change: MiNT Programmer's Manual 2